package com.yuanxuzhen.ijkplayerdemo;

import android.content.Context;
import android.os.Environment;
import android.text.TextUtils;


import java.io.File;

public class DirUtil {
    public static final String WEBVIEW_CACHE = ".webviewCache";
    public static final String IMAGE_PATH = "image";
    public static final String DOWNLOAD_PATH = "download";
    public static final String VIDEO_PATH = ".video";
    public static final String NET_PATH = ".net";


    //image
    public static String getImageDir(Context context) {
        return getCacheDir(context) + File.separator + IMAGE_PATH;
    }

    //webview
    public static String getWebviewCache(Context context) {
        return getCacheDir(context) + File.separator + WEBVIEW_CACHE;
    }

    //download
    public static String getDownloadDir(Context context) {
        return getCacheDir(context) + File.separator + DOWNLOAD_PATH;
    }

    //video
    public static String getVideoPath(Context context) {
        return getCacheDir(context) + File.separator + VIDEO_PATH;
    }

    //net
    public static String getNetPath(Context context) {
        return getCacheDir(context) + File.separator + NET_PATH;
    }


    public static String getCacheDir(Context context) {

        if (context == null) {
            return "";
        }
        String path = null;
        if (context.getExternalCacheDir() != null
                && (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                || !Environment.isExternalStorageRemovable())) {
            //外部存储可用
            path = context.getExternalCacheDir().getPath();
        } else {
            //内部存储不可用
            path = context.getCacheDir().getPath();
        }
        return path;
    }




}
